package com.example.demo.compile;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-10-11
 * Time:10:33
 */

class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
public class Solution {
    //用户提交的代码
    public ListNode ReverseList(ListNode head) {
        ListNode pre = null;
        while(head != null) {
            ListNode cur = head.next;
            head.next = pre;
            pre = head;
            head = cur;
        }
        return pre;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] arr ={{1,2,3,4,5},{2,3,4,5,6},{9,8,7,6,5}};
        int caseCount = arr.length;
        int passCount = 0;
        for(int i = 0;i<arr.length;i++) {
            ListNode head = solution.Construction(arr[i]);
            ListNode cur = solution.Construction(arr[i]);
            ListNode head1 = solution.ReverseList(head);
            ListNode head2 = solution.ReverseList1(cur);
            while (head1 != null && head2 != null) {
                if(head1.val != head2.val) {
                    System.out.println("用例通过："+ passCount + "/" + caseCount);
                    return;
                }
                head1 = head1.next;
                head2 = head2.next;
            }
            if(head1 != null || head2 != null) {
                System.out.println("用例通过："+ passCount + "/" + caseCount);
                return;
            }
            passCount = passCount + 1;
        }
        System.out.println("运行通过！");
    }
    //标准代码
    public ListNode ReverseList1(ListNode head) {
        ListNode pre = null;
        while(head != null) {
            ListNode cur = head.next;
            head.next = pre;
            pre = head;
            head = cur;
        }
        return pre;
    }
    //链表集合
    public ListNode Construction(int[] arr) {
        ListNode head = new ListNode(arr[0]);
        ListNode cur = head;
        for (int i = 1;i<arr.length;i++) {
            cur.next = new ListNode(arr[i]);
            cur = cur.next;
        }
        return head;
    }
}